package com.ruoyi.puyu.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.puyu.domain.PuyuMatchSchedule;
import com.ruoyi.puyu.mapper.PuyuMatchScheduleMapper;
import com.ruoyi.puyu.service.IPuyuMatchScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 赛程Service业务层处理
 * 
 * @author wusongwen
 * @date 2024-12-25
 */
@Service
public class PuyuMatchScheduleServiceImpl implements IPuyuMatchScheduleService 
{
    @Autowired
    private PuyuMatchScheduleMapper puyuMatchScheduleMapper;

    /**
     * 查询赛程
     * 
     * @param scheduleId 赛程主键
     * @return 赛程
     */
    @Override
    public PuyuMatchSchedule selectPuyuMatchScheduleByScheduleId(Long scheduleId)
    {
        return puyuMatchScheduleMapper.selectPuyuMatchScheduleByScheduleId(scheduleId);
    }

    @Override
    public Map<String, Object> getNavigation(Long currentId) {
        return new HashMap<String, Object>(){{
            put("prev", wrapPuyuMatchSchedule(puyuMatchScheduleMapper.findPreviousPuyuMatchSchedule(currentId)));
            put("next", wrapPuyuMatchSchedule(puyuMatchScheduleMapper.findNextPuyuMatchSchedule(currentId)));
        }};
    }

    /**
     * 查询赛程列表
     * 
     * @param puyuMatchSchedule 赛程
     * @return 赛程
     */
    @Override
    public List<PuyuMatchSchedule> selectPuyuMatchScheduleList(PuyuMatchSchedule puyuMatchSchedule)
    {
        return puyuMatchScheduleMapper.selectPuyuMatchScheduleList(puyuMatchSchedule);
    }

    /**
     * 新增赛程
     * 
     * @param puyuMatchSchedule 赛程
     * @return 结果
     */
    @Override
    public int insertPuyuMatchSchedule(PuyuMatchSchedule puyuMatchSchedule)
    {
        puyuMatchSchedule.setCreateTime(DateUtils.getNowDate());
        return puyuMatchScheduleMapper.insertPuyuMatchSchedule(puyuMatchSchedule);
    }

    /**
     * 修改赛程
     * 
     * @param puyuMatchSchedule 赛程
     * @return 结果
     */
    @Override
    public int updatePuyuMatchSchedule(PuyuMatchSchedule puyuMatchSchedule)
    {
        puyuMatchSchedule.setUpdateBy(SecurityUtils.getUsername());
        puyuMatchSchedule.setUpdateTime(DateUtils.getNowDate());
        return puyuMatchScheduleMapper.updatePuyuMatchSchedule(puyuMatchSchedule);
    }

    /**
     * 批量删除赛程
     * 
     * @param scheduleIds 需要删除的赛程主键
     * @return 结果
     */
    @Override
    public int deletePuyuMatchScheduleByScheduleIds(Long[] scheduleIds)
    {
        return puyuMatchScheduleMapper.deletePuyuMatchScheduleByScheduleIds(scheduleIds);
    }

    /**
     * 删除赛程信息
     * 
     * @param scheduleId 赛程主键
     * @return 结果
     */
    @Override
    public int deletePuyuMatchScheduleByScheduleId(Long scheduleId)
    {
        return puyuMatchScheduleMapper.deletePuyuMatchScheduleByScheduleId(scheduleId);
    }

    private Map<String, Object> wrapPuyuMatchSchedule(PuyuMatchSchedule puyuMatchSchedule) {
        if(null == puyuMatchSchedule) {
            return null;
        }

        return new HashMap<String, Object>(){{
            put("scheduleId", puyuMatchSchedule.getScheduleId());
            put("scheduleTitle", puyuMatchSchedule.getScheduleTitle());
            put("createTime", puyuMatchSchedule.getCreateTime());
        }};
    }
}
